import socket
import threading
import logging
IPs = [b"192.168.000.001",b"127.000.000.001",b"none"]
Ports = [b"80",b"2300",b"none"]
def hash(order):
    if order == b"http":
        return 0
    elif order == b"ftp":
        return 1
    else:
        return 2
def ser( socket, addr ):
    try:
        order = socket.recv(1080)
        ip = IPs[hash(order)]
        port = Ports[hash(order)]
        socket.send(ip)
        socket.send(port)
        print("查询：",order)
        logging.info(order)
        logging.info(addr)
    except:
        pass
    socket.close()
def init():
    print("DDNS服务已启动\n")
    s = socket.socket()
    host = socket.gethostbyname(socket.gethostname())
    port = 1234
    print("服务器地址：(",host,",",port,")")
    s.bind(( host,port ))
    logging.basicConfig(level=logging.INFO,filename='ServerLog.txt')
    print("初始化已完成，正在监听...")
    while True:
        s.listen()
        c, addr = s.accept()
        thread = threading.Thread(target = ser, args = ( c, addr ))
        thread.start()
init()
